/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>

#include "dal/allocator.h"
#include "dal/utils.h"

TEST(dal_allocate_free, test_dal_allocator)
{
    void* ptr = dal_allocate(100u);
    EXPECT_NE(ptr, nullptr);
    dal_free(ptr);
}

TEST(dal_domain_participant_allocate_free, test_dal_allocator)
{
    dal_domain_participant_t* ptr = dal_domain_participant_allocate();
    EXPECT_NE(ptr, nullptr);
    dal_domain_participant_free(ptr);
}

TEST(dal_topic_allocate_free, test_dal_allocator)
{
    dal_topic_t* ptr = dal_topic_allocate();
    EXPECT_NE(ptr, nullptr);
    dal_topic_free(ptr);
}

TEST(dal_pubsub_allocate_free, test_dal_allocator)
{
    dal_publisher_t* pub_ptr = dal_publisher_allocate();
    EXPECT_NE(pub_ptr, nullptr);
    dal_publisher_free(pub_ptr);

    dal_subscriber_t* sub_ptr = dal_subscriber_allocate();
    EXPECT_NE(sub_ptr, nullptr);
    dal_subscriber_free(sub_ptr);

    dal_datawriter_t* writer_ptr = dal_datawriter_allocate();
    EXPECT_NE(writer_ptr, nullptr);
    dal_datawriter_free(writer_ptr);

    dal_datareader_t* reader_ptr = dal_datareader_allocate();
    EXPECT_NE(reader_ptr, nullptr);
    dal_datareader_free(reader_ptr);
}

TEST(dal_listener_allocate_free, test_dal_allocator)
{
    dal_domain_participant_listener_t* ptr = dal_domain_participant_listener_allocate();
    EXPECT_NE(ptr, nullptr);
    dal_domain_participant_listener_free(ptr);
}

TEST(dal_qos_allocate_free, test_dal_allocator)
{
    dal_domain_participant_qos_t* participant_qos_ptr = dal_domain_participant_qos_allocate();
    EXPECT_NE(participant_qos_ptr, nullptr);
    dal_domain_participant_qos_free(participant_qos_ptr);

    dal_topic_qos_t* topic_qos_ptr = dal_topic_qos_allocate();
    EXPECT_NE(topic_qos_ptr, nullptr);
    dal_topic_qos_free(topic_qos_ptr);

    dal_publisher_qos_t* pub_qos_ptr = dal_publisher_qos_allocate();
    EXPECT_NE(pub_qos_ptr, nullptr);
    dal_publisher_qos_free(pub_qos_ptr);

    dal_subscriber_qos_t* sub_qos_ptr = dal_subscriber_qos_allocate();
    EXPECT_NE(sub_qos_ptr, nullptr);
    dal_subscriber_qos_free(sub_qos_ptr);

    dal_datawriter_qos_t* writer_qos_ptr = dal_datawriter_qos_allocate();
    EXPECT_NE(writer_qos_ptr, nullptr);
    dal_datawriter_qos_free(writer_qos_ptr);

    dal_datareader_qos_t* reader_qos_ptr = dal_datareader_qos_allocate();
    EXPECT_NE(reader_qos_ptr, nullptr);
    dal_datareader_qos_free(reader_qos_ptr);
}
